$(function() {
    getUserinfo()
    $('#btnReset').on('click', getUserinfo)
    $('.layui-form').on('submit', dosubmit)
})

function getUserinfo() {
    $.ajax({
        url: '/my/userinfo',
        success(res) {
            if (res.status !== 0) {
                layui.layer.msg(res.message)
                return
            }
            layui.form.val('userForm', res.data)
        }
    })
}

function dosubmit(e) {
    e.preventDefault()
    const data = $(this).serialize()
    $.ajax({
        method: 'post',
        url: '/my/userinfo',
        data,
        success(res) {
            if (res.status !== 0) return layui.layer.msg(res.message)
            window.parent.getUserinfo()
        }
    })
}